package com.example.myapplication.logisticsinquiry;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.OKHttpTool;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.LogisticscompanyBean;

import java.util.List;

public class LogisticscompanyActivity extends AppCompatActivity {

    private ImageView img;
    private TextView phone;
    private TextView shippingMethod;
    private TextView introduce;
    private ImageView imgUrl;
    private String stringExtra;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logisticscompany);
        Intent intent = getIntent();
        stringExtra = intent.getStringExtra(Commom.LogisticscompanID);
        initview();
        //返回
        but_bloak();
        //详情介绍
        logisticscompany();
    }

    private void logisticscompany() {
        OKHttpTool.doNetRequest("prod-api/api/logistics-inquiry/logistics_company/" + stringExtra,
                OKHttpTool.GET,
                LogisticscompanyBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                LogisticscompanyBean logisticscompanyBean  = (LogisticscompanyBean)obj;
                                if(logisticscompanyBean.getCode()==200){
                                    LogisticscompanyBean.DataBean data = logisticscompanyBean.getData();
                                    Glide.with(LogisticscompanyActivity.this).load(TokenBean.IP+data.getImgUrl()).into(imgUrl);
                                    introduce.setText(data.getIntroduce());
                                    shippingMethod.setText(data.getShippingMethod());
                                    phone.setText(data.getPhone());
                                }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void but_bloak() {
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogisticscompanyActivity.this.finish();
            }
        });
    }

    private void initview() {
        img = findViewById(R.id.img);
        imgUrl = findViewById(R.id.imgUrl);
        introduce = findViewById(R.id.introduce);
        shippingMethod = findViewById(R.id.shippingMethod);
        phone = findViewById(R.id.phone);
    }
}